package com.ktgj.train.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.train.domain.TrainAreainfo;
import com.ktgj.train.service.ITrainAreainfoService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 地区信息Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@ControllerAdvice
@RestController
@RequestMapping("/areainfo")
public class TrainAreainfoController extends BaseController
{
    @Autowired
    private ITrainAreainfoService trainAreainfoService;

    /**
     * 查询地区信息列表
     */
    //@PreAuthorize(hasPermi = "train:areainfo:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainAreainfo trainAreainfo)
    {
        startPage();
        List<TrainAreainfo> list = trainAreainfoService.selectTrainAreainfoList(trainAreainfo);
        return getDataTable(list);
    }

    /**
     * 导出地区信息列表
     */
    @PreAuthorize(hasPermi = "train:areainfo:export")
    @Log(title = "地区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainAreainfo trainAreainfo) throws IOException
    {
        List<TrainAreainfo> list = trainAreainfoService.selectTrainAreainfoList(trainAreainfo);
        ExcelUtil<TrainAreainfo> util = new ExcelUtil<TrainAreainfo>(TrainAreainfo.class);
        util.exportExcel(response, list, "地区信息数据");
    }

    /**
     * 获取地区信息详细信息
     */
    @PreAuthorize(hasPermi = "train:areainfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(trainAreainfoService.selectTrainAreainfoById(id));
    }

    /**
     * 新增地区信息
     */
    @PreAuthorize(hasPermi = "train:areainfo:add")
    @Log(title = "地区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainAreainfo trainAreainfo)
    {
        return toAjax(trainAreainfoService.insertTrainAreainfo(trainAreainfo));
    }

    /**
     * 修改地区信息
     */
    @PreAuthorize(hasPermi = "train:areainfo:edit")
    @Log(title = "地区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainAreainfo trainAreainfo)
    {
        return toAjax(trainAreainfoService.updateTrainAreainfo(trainAreainfo));
    }

    /**
     * 删除地区信息
     */
    @PreAuthorize(hasPermi = "train:areainfo:remove")
    @Log(title = "地区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainAreainfoService.deleteTrainAreainfoByIds(ids));
    }
}
